<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :editData="editData"
               :url="$api.seckill_getlist"
               :new_url="this.$api.seckill_insert"
               :detail_url="this.$api.seckill_info"
               :edit_url="this.$api.seckill_save"
               :is_default_edit="true"
               label-width="140px"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "type",
          label: "秒杀类型",
          value: "",
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '平台卡券',
              value: '1'
            },
            {
              label: '实物或其他',
              value: '2'
            },
          ]
        },
        {
          name: "start_time",
          label: "开始时间",
          value: '',
          type: "date_time_picker",
          config: {
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            'value-format': 'yyyy-MM-dd HH:mm:ss',
          }
        },
        {
          name: "end_time",
          label: "结束时间",
          value: '',
          type: "date_time_picker",
          config: {
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            'value-format': 'yyyy-MM-dd HH:mm:ss',
          }
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: 'select',
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '隐藏',
              value: '0'
            },
            {
              label: '显示',
              value: '1'
            },
          ]
        },
      ],
      columnData: [
        {
          prop: "seckill_id",
          label: "id"
        },
        {
          prop: "goods_name",
          label: "商品标题"
        },
        {
          prop: "sale_price",
          label: "秒杀价格"
        },
        {
          prop: "price",
          label: "商品权益价格"
        },
        {
          prop: "type",
          label: "活动类型",
          custom: true,
          type: 'status',
          active_val: '1',
          active_text: '平台卡券',
          active_not_text: '实物或其他'
        },
        {
          prop: "limit_num",
          label: "秒杀商品数量"
        },
        {
          prop: "remain_num",
          label: "剩余数量"
        },
        {
          prop: "start_time",
          label: "开始时间",
          width: '180px'
        },
        {
          prop: "end_time",
          label: "结束时间",
          width: '180px'
        },
        {
          prop: "display",
          label: "是否显示",
          custom: true,
          type: 'switch',
          url: this.$api.seckill_status
        },
        {
          prop: 'btn_group',
          label: '操作',
          custom: true,
          type: 'btn_group',
          width: '200px',
          group: [
            {
              name: '编辑',
              type: 'edit',
              color: 'primary',
              detail_mark: 'seckill_id',
            },
            {
              name: '删除',
              type: 'delete',
              color: 'danger',
              url: this.$api.seckill_status
            }
          ]
        }
      ],
      editData: [
        {
          name: 'seckill_id',
          label: '秒杀id',
          value: '',
          type: 'input',
          display: 'none'
        },
        {
          name: "connect_id",
          label: "权益名称",
          value: '',
          type: "select",
          groups: [],
          config: {
            filterable: true
          },
          rules: [
            { required: true, message: "请选择权益名称", trigger: "blur" },
          ]
        },
        {
          name: 'sale_price',
          label: '秒杀价格',
          value: '',
          type: 'input',
          rules: [
            { required: true, message: "请填写秒杀价格", trigger: "blur" },
          ]
        },
        {
          name: "type",
          label: "活动类型",
          value: "",
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '平台卡券',
              value: '1'
            },
            {
              label: '实物或其他',
              value: '2'
            },
          ],
          rules: [
            { required: true, message: "请选择活动类型", trigger: "blur" },
          ]
        },
        {
          name: 'limit_num',
          label: '秒杀商品数量',
          value: '',
          datatype:'number',
          type: 'input',
          rules: [
            { required: true, message: "请填写秒杀商品数量", trigger: "blur" },
            { type: 'number', message: '秒杀商品数量必须为数字值'},
          ]
        },
        {
          name: "start_time",
          label: "开始时间",
          value: '',
          type: "date_time_picker",
          config: {
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            'value-format': 'yyyy-MM-dd HH:mm:ss',
          },
          rules: [
            { required: true, message: "请选择开始时间", trigger: "blur" },
          ]
        },
        {
          name: "end_time",
          label: "结束时间",
          value: '',
          type: "date_time_picker",
          config: {
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            'value-format': 'yyyy-MM-dd HH:mm:ss',
          },
          rules: [
            { required: true, message: "请选择结束时间", trigger: "blur" },
          ]
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: 'switch',
          config: {
            'active_value': '1',
            'inactive-value': '0'
          }
        },
      ],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.getCard();
  },
  methods: {
    getCard () {
      this.$req.get(this.$api.card_getnopagelist).then(res => {
        let data = res.data;
        for (var i in data) {
          this.editData[1].groups.push({
            label: data[i].name,
            value: data[i].card_id
          })
        }
      })
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>